<?php


abstract class BaseProducts extends BaseObject  implements Persistent {


  const PEER = 'ProductsPeer';

	
	protected static $peer;

	
	protected $id;

	
	protected $reference;

	
	protected $code;

	
	protected $codetype;

	
	protected $name;

	
	protected $pricebuy;

	
	protected $pricesell;

	
	protected $category;

	
	protected $taxcat;

	
	protected $stockcost;

	
	protected $stockvolume;

	
	protected $image;

	
	protected $iscom;

	
	protected $isscale;

	
	protected $attributes;

	
	protected $aCategories;

	
	protected $aTaxcategories;

	
	protected $singleProductsCat;

	
	protected $collProductsComsRelatedByProduct;

	
	private $lastProductsComRelatedByProductCriteria = null;

	
	protected $collProductsComsRelatedByProduct2;

	
	private $lastProductsComRelatedByProduct2Criteria = null;

	
	protected $collStockcurrents;

	
	private $lastStockcurrentCriteria = null;

	
	protected $collStockdiarys;

	
	private $lastStockdiaryCriteria = null;

	
	protected $collTicketliness;

	
	private $lastTicketlinesCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function __construct()
	{
		parent::__construct();
		$this->applyDefaultValues();
	}

	
	public function applyDefaultValues()
	{
	}

	
	public function getId()
	{
		return $this->id;
	}

	
	public function getReference()
	{
		return $this->reference;
	}

	
	public function getCode()
	{
		return $this->code;
	}

	
	public function getCodetype()
	{
		return $this->codetype;
	}

	
	public function getName()
	{
		return $this->name;
	}

	
	public function getPricebuy()
	{
		return $this->pricebuy;
	}

	
	public function getPricesell()
	{
		return $this->pricesell;
	}

	
	public function getCategory()
	{
		return $this->category;
	}

	
	public function getTaxcat()
	{
		return $this->taxcat;
	}

	
	public function getStockcost()
	{
		return $this->stockcost;
	}

	
	public function getStockvolume()
	{
		return $this->stockvolume;
	}

	
	public function getImage()
	{
		return $this->image;
	}

	
	public function getIscom()
	{
		return $this->iscom;
	}

	
	public function getIsscale()
	{
		return $this->isscale;
	}

	
	public function getAttributes()
	{
		return $this->attributes;
	}

	
	public function setId($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = ProductsPeer::ID;
		}

		return $this;
	} 
	
	public function setReference($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->reference !== $v) {
			$this->reference = $v;
			$this->modifiedColumns[] = ProductsPeer::REFERENCE;
		}

		return $this;
	} 
	
	public function setCode($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->code !== $v) {
			$this->code = $v;
			$this->modifiedColumns[] = ProductsPeer::CODE;
		}

		return $this;
	} 
	
	public function setCodetype($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->codetype !== $v) {
			$this->codetype = $v;
			$this->modifiedColumns[] = ProductsPeer::CODETYPE;
		}

		return $this;
	} 
	
	public function setName($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->name !== $v) {
			$this->name = $v;
			$this->modifiedColumns[] = ProductsPeer::NAME;
		}

		return $this;
	} 
	
	public function setPricebuy($v)
	{
		if ($v !== null) {
			$v = (double) $v;
		}

		if ($this->pricebuy !== $v) {
			$this->pricebuy = $v;
			$this->modifiedColumns[] = ProductsPeer::PRICEBUY;
		}

		return $this;
	} 
	
	public function setPricesell($v)
	{
		if ($v !== null) {
			$v = (double) $v;
		}

		if ($this->pricesell !== $v) {
			$this->pricesell = $v;
			$this->modifiedColumns[] = ProductsPeer::PRICESELL;
		}

		return $this;
	} 
	
	public function setCategory($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->category !== $v) {
			$this->category = $v;
			$this->modifiedColumns[] = ProductsPeer::CATEGORY;
		}

		if ($this->aCategories !== null && $this->aCategories->getId() !== $v) {
			$this->aCategories = null;
		}

		return $this;
	} 
	
	public function setTaxcat($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->taxcat !== $v) {
			$this->taxcat = $v;
			$this->modifiedColumns[] = ProductsPeer::TAXCAT;
		}

		if ($this->aTaxcategories !== null && $this->aTaxcategories->getId() !== $v) {
			$this->aTaxcategories = null;
		}

		return $this;
	} 
	
	public function setStockcost($v)
	{
		if ($v !== null) {
			$v = (double) $v;
		}

		if ($this->stockcost !== $v) {
			$this->stockcost = $v;
			$this->modifiedColumns[] = ProductsPeer::STOCKCOST;
		}

		return $this;
	} 
	
	public function setStockvolume($v)
	{
		if ($v !== null) {
			$v = (double) $v;
		}

		if ($this->stockvolume !== $v) {
			$this->stockvolume = $v;
			$this->modifiedColumns[] = ProductsPeer::STOCKVOLUME;
		}

		return $this;
	} 
	
	public function setImage($v)
	{
								if (!is_resource($v)) {
			$this->image = fopen('php://memory', 'r+');
			fwrite($this->image, $v);
			rewind($this->image);
		} else { 			$this->image = $v;
		}
		$this->modifiedColumns[] = ProductsPeer::IMAGE;

		return $this;
	} 
	
	public function setIscom($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->iscom !== $v) {
			$this->iscom = $v;
			$this->modifiedColumns[] = ProductsPeer::ISCOM;
		}

		return $this;
	} 
	
	public function setIsscale($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->isscale !== $v) {
			$this->isscale = $v;
			$this->modifiedColumns[] = ProductsPeer::ISSCALE;
		}

		return $this;
	} 
	
	public function setAttributes($v)
	{
								if (!is_resource($v)) {
			$this->attributes = fopen('php://memory', 'r+');
			fwrite($this->attributes, $v);
			rewind($this->attributes);
		} else { 			$this->attributes = $v;
		}
		$this->modifiedColumns[] = ProductsPeer::ATTRIBUTES;

		return $this;
	} 
	
	public function hasOnlyDefaultValues()
	{
						if (array_diff($this->modifiedColumns, array())) {
				return false;
			}

				return true;
	} 
	
	public function hydrate($row, $startcol = 0, $rehydrate = false)
	{
		try {

			$this->id = ($row[$startcol + 0] !== null) ? (string) $row[$startcol + 0] : null;
			$this->reference = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
			$this->code = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
			$this->codetype = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
			$this->name = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
			$this->pricebuy = ($row[$startcol + 5] !== null) ? (double) $row[$startcol + 5] : null;
			$this->pricesell = ($row[$startcol + 6] !== null) ? (double) $row[$startcol + 6] : null;
			$this->category = ($row[$startcol + 7] !== null) ? (string) $row[$startcol + 7] : null;
			$this->taxcat = ($row[$startcol + 8] !== null) ? (string) $row[$startcol + 8] : null;
			$this->stockcost = ($row[$startcol + 9] !== null) ? (double) $row[$startcol + 9] : null;
			$this->stockvolume = ($row[$startcol + 10] !== null) ? (double) $row[$startcol + 10] : null;
			if ($row[$startcol + 11] !== null) {
				$this->image = fopen('php://memory', 'r+');
				fwrite($this->image, $row[$startcol + 11]);
				rewind($this->image);
			} else {
				$this->image = null;
			}
			$this->iscom = ($row[$startcol + 12] !== null) ? (string) $row[$startcol + 12] : null;
			$this->isscale = ($row[$startcol + 13] !== null) ? (string) $row[$startcol + 13] : null;
			if ($row[$startcol + 14] !== null) {
				$this->attributes = fopen('php://memory', 'r+');
				fwrite($this->attributes, $row[$startcol + 14]);
				rewind($this->attributes);
			} else {
				$this->attributes = null;
			}
			$this->resetModified();

			$this->setNew(false);

			if ($rehydrate) {
				$this->ensureConsistency();
			}

						return $startcol + 15; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Products object", $e);
		}
	}

	
	public function ensureConsistency()
	{

		if ($this->aCategories !== null && $this->category !== $this->aCategories->getId()) {
			$this->aCategories = null;
		}
		if ($this->aTaxcategories !== null && $this->taxcat !== $this->aTaxcategories->getId()) {
			$this->aTaxcategories = null;
		}
	} 
	
	public function reload($deep = false, PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("Cannot reload a deleted object.");
		}

		if ($this->isNew()) {
			throw new PropelException("Cannot reload an unsaved object.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ProductsPeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}

				
		$stmt = ProductsPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
		$row = $stmt->fetch(PDO::FETCH_NUM);
		$stmt->closeCursor();
		if (!$row) {
			throw new PropelException('Cannot find matching row in the database to reload object values.');
		}
		$this->hydrate($row, 0, true); 
		if ($deep) {  
			$this->aCategories = null;
			$this->aTaxcategories = null;
			$this->singleProductsCat = null;

			$this->collProductsComsRelatedByProduct = null;
			$this->lastProductsComRelatedByProductCriteria = null;

			$this->collProductsComsRelatedByProduct2 = null;
			$this->lastProductsComRelatedByProduct2Criteria = null;

			$this->collStockcurrents = null;
			$this->lastStockcurrentCriteria = null;

			$this->collStockdiarys = null;
			$this->lastStockdiaryCriteria = null;

			$this->collTicketliness = null;
			$this->lastTicketlinesCriteria = null;

		} 	}

	
	public function delete(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ProductsPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			ProductsPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollBack();
			throw $e;
		}
	}

	
	public function save(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ProductsPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			$affectedRows = $this->doSave($con);
			$con->commit();
			ProductsPeer::addInstanceToPool($this);
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollBack();
			throw $e;
		}
	}

	
	protected function doSave(PropelPDO $con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;

												
			if ($this->aCategories !== null) {
				if ($this->aCategories->isModified() || $this->aCategories->isNew()) {
					$affectedRows += $this->aCategories->save($con);
				}
				$this->setCategories($this->aCategories);
			}

			if ($this->aTaxcategories !== null) {
				if ($this->aTaxcategories->isModified() || $this->aTaxcategories->isNew()) {
					$affectedRows += $this->aTaxcategories->save($con);
				}
				$this->setTaxcategories($this->aTaxcategories);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = ProductsPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setNew(false);
				} else {
					$affectedRows += ProductsPeer::doUpdate($this, $con);
				}

								if ($this->image !== null && is_resource($this->image)) {
					rewind($this->image);
				}

								if ($this->attributes !== null && is_resource($this->attributes)) {
					rewind($this->attributes);
				}

				$this->resetModified(); 			}

			if ($this->singleProductsCat !== null) {
				if (!$this->singleProductsCat->isDeleted()) {
						$affectedRows += $this->singleProductsCat->save($con);
				}
			}

			if ($this->collProductsComsRelatedByProduct !== null) {
				foreach ($this->collProductsComsRelatedByProduct as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collProductsComsRelatedByProduct2 !== null) {
				foreach ($this->collProductsComsRelatedByProduct2 as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collStockcurrents !== null) {
				foreach ($this->collStockcurrents as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collStockdiarys !== null) {
				foreach ($this->collStockdiarys as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collTicketliness !== null) {
				foreach ($this->collTicketliness as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;

		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->aCategories !== null) {
				if (!$this->aCategories->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aCategories->getValidationFailures());
				}
			}

			if ($this->aTaxcategories !== null) {
				if (!$this->aTaxcategories->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aTaxcategories->getValidationFailures());
				}
			}


			if (($retval = ProductsPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->singleProductsCat !== null) {
					if (!$this->singleProductsCat->validate($columns)) {
						$failureMap = array_merge($failureMap, $this->singleProductsCat->getValidationFailures());
					}
				}

				if ($this->collProductsComsRelatedByProduct !== null) {
					foreach ($this->collProductsComsRelatedByProduct as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collProductsComsRelatedByProduct2 !== null) {
					foreach ($this->collProductsComsRelatedByProduct2 as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collStockcurrents !== null) {
					foreach ($this->collStockcurrents as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collStockdiarys !== null) {
					foreach ($this->collStockdiarys as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collTicketliness !== null) {
					foreach ($this->collTicketliness as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = ProductsPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		$field = $this->getByPosition($pos);
		return $field;
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getReference();
				break;
			case 2:
				return $this->getCode();
				break;
			case 3:
				return $this->getCodetype();
				break;
			case 4:
				return $this->getName();
				break;
			case 5:
				return $this->getPricebuy();
				break;
			case 6:
				return $this->getPricesell();
				break;
			case 7:
				return $this->getCategory();
				break;
			case 8:
				return $this->getTaxcat();
				break;
			case 9:
				return $this->getStockcost();
				break;
			case 10:
				return $this->getStockvolume();
				break;
			case 11:
				return $this->getImage();
				break;
			case 12:
				return $this->getIscom();
				break;
			case 13:
				return $this->getIsscale();
				break;
			case 14:
				return $this->getAttributes();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
	{
		$keys = ProductsPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getReference(),
			$keys[2] => $this->getCode(),
			$keys[3] => $this->getCodetype(),
			$keys[4] => $this->getName(),
			$keys[5] => $this->getPricebuy(),
			$keys[6] => $this->getPricesell(),
			$keys[7] => $this->getCategory(),
			$keys[8] => $this->getTaxcat(),
			$keys[9] => $this->getStockcost(),
			$keys[10] => $this->getStockvolume(),
			$keys[11] => $this->getImage(),
			$keys[12] => $this->getIscom(),
			$keys[13] => $this->getIsscale(),
			$keys[14] => $this->getAttributes(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = ProductsPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setReference($value);
				break;
			case 2:
				$this->setCode($value);
				break;
			case 3:
				$this->setCodetype($value);
				break;
			case 4:
				$this->setName($value);
				break;
			case 5:
				$this->setPricebuy($value);
				break;
			case 6:
				$this->setPricesell($value);
				break;
			case 7:
				$this->setCategory($value);
				break;
			case 8:
				$this->setTaxcat($value);
				break;
			case 9:
				$this->setStockcost($value);
				break;
			case 10:
				$this->setStockvolume($value);
				break;
			case 11:
				$this->setImage($value);
				break;
			case 12:
				$this->setIscom($value);
				break;
			case 13:
				$this->setIsscale($value);
				break;
			case 14:
				$this->setAttributes($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = ProductsPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setReference($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setCode($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setCodetype($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setName($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setPricebuy($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setPricesell($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setCategory($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setTaxcat($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setStockcost($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setStockvolume($arr[$keys[10]]);
		if (array_key_exists($keys[11], $arr)) $this->setImage($arr[$keys[11]]);
		if (array_key_exists($keys[12], $arr)) $this->setIscom($arr[$keys[12]]);
		if (array_key_exists($keys[13], $arr)) $this->setIsscale($arr[$keys[13]]);
		if (array_key_exists($keys[14], $arr)) $this->setAttributes($arr[$keys[14]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(ProductsPeer::DATABASE_NAME);

		if ($this->isColumnModified(ProductsPeer::ID)) $criteria->add(ProductsPeer::ID, $this->id);
		if ($this->isColumnModified(ProductsPeer::REFERENCE)) $criteria->add(ProductsPeer::REFERENCE, $this->reference);
		if ($this->isColumnModified(ProductsPeer::CODE)) $criteria->add(ProductsPeer::CODE, $this->code);
		if ($this->isColumnModified(ProductsPeer::CODETYPE)) $criteria->add(ProductsPeer::CODETYPE, $this->codetype);
		if ($this->isColumnModified(ProductsPeer::NAME)) $criteria->add(ProductsPeer::NAME, $this->name);
		if ($this->isColumnModified(ProductsPeer::PRICEBUY)) $criteria->add(ProductsPeer::PRICEBUY, $this->pricebuy);
		if ($this->isColumnModified(ProductsPeer::PRICESELL)) $criteria->add(ProductsPeer::PRICESELL, $this->pricesell);
		if ($this->isColumnModified(ProductsPeer::CATEGORY)) $criteria->add(ProductsPeer::CATEGORY, $this->category);
		if ($this->isColumnModified(ProductsPeer::TAXCAT)) $criteria->add(ProductsPeer::TAXCAT, $this->taxcat);
		if ($this->isColumnModified(ProductsPeer::STOCKCOST)) $criteria->add(ProductsPeer::STOCKCOST, $this->stockcost);
		if ($this->isColumnModified(ProductsPeer::STOCKVOLUME)) $criteria->add(ProductsPeer::STOCKVOLUME, $this->stockvolume);
		if ($this->isColumnModified(ProductsPeer::IMAGE)) $criteria->add(ProductsPeer::IMAGE, $this->image);
		if ($this->isColumnModified(ProductsPeer::ISCOM)) $criteria->add(ProductsPeer::ISCOM, $this->iscom);
		if ($this->isColumnModified(ProductsPeer::ISSCALE)) $criteria->add(ProductsPeer::ISSCALE, $this->isscale);
		if ($this->isColumnModified(ProductsPeer::ATTRIBUTES)) $criteria->add(ProductsPeer::ATTRIBUTES, $this->attributes);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(ProductsPeer::DATABASE_NAME);

		$criteria->add(ProductsPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setId($this->id);

		$copyObj->setReference($this->reference);

		$copyObj->setCode($this->code);

		$copyObj->setCodetype($this->codetype);

		$copyObj->setName($this->name);

		$copyObj->setPricebuy($this->pricebuy);

		$copyObj->setPricesell($this->pricesell);

		$copyObj->setCategory($this->category);

		$copyObj->setTaxcat($this->taxcat);

		$copyObj->setStockcost($this->stockcost);

		$copyObj->setStockvolume($this->stockvolume);

		$copyObj->setImage($this->image);

		$copyObj->setIscom($this->iscom);

		$copyObj->setIsscale($this->isscale);

		$copyObj->setAttributes($this->attributes);


		if ($deepCopy) {
									$copyObj->setNew(false);

			$relObj = $this->getProductsCat();
			if ($relObj) {
				$copyObj->setProductsCat($relObj->copy($deepCopy));
			}

			foreach ($this->getProductsComsRelatedByProduct() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addProductsComRelatedByProduct($relObj->copy($deepCopy));
				}
			}

			foreach ($this->getProductsComsRelatedByProduct2() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addProductsComRelatedByProduct2($relObj->copy($deepCopy));
				}
			}

			foreach ($this->getStockcurrents() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addStockcurrent($relObj->copy($deepCopy));
				}
			}

			foreach ($this->getStockdiarys() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addStockdiary($relObj->copy($deepCopy));
				}
			}

			foreach ($this->getTicketliness() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addTicketlines($relObj->copy($deepCopy));
				}
			}

		} 

		$copyObj->setNew(true);

	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new ProductsPeer();
		}
		return self::$peer;
	}

	
	public function setCategories(Categories $v = null)
	{
		if ($v === null) {
			$this->setCategory(NULL);
		} else {
			$this->setCategory($v->getId());
		}

		$this->aCategories = $v;

						if ($v !== null) {
			$v->addProducts($this);
		}

		return $this;
	}


	
	public function getCategories(PropelPDO $con = null)
	{
		if ($this->aCategories === null && (($this->category !== "" && $this->category !== null))) {
			$c = new Criteria(CategoriesPeer::DATABASE_NAME);
			$c->add(CategoriesPeer::ID, $this->category);
			$this->aCategories = CategoriesPeer::doSelectOne($c, $con);
			
		}
		return $this->aCategories;
	}

	
	public function setTaxcategories(Taxcategories $v = null)
	{
		if ($v === null) {
			$this->setTaxcat(NULL);
		} else {
			$this->setTaxcat($v->getId());
		}

		$this->aTaxcategories = $v;

						if ($v !== null) {
			$v->addProducts($this);
		}

		return $this;
	}


	
	public function getTaxcategories(PropelPDO $con = null)
	{
		if ($this->aTaxcategories === null && (($this->taxcat !== "" && $this->taxcat !== null))) {
			$c = new Criteria(TaxcategoriesPeer::DATABASE_NAME);
			$c->add(TaxcategoriesPeer::ID, $this->taxcat);
			$this->aTaxcategories = TaxcategoriesPeer::doSelectOne($c, $con);
			
		}
		return $this->aTaxcategories;
	}

	
	public function getProductsCat(PropelPDO $con = null)
	{

		if ($this->singleProductsCat === null && !$this->isNew()) {
			$this->singleProductsCat = ProductsCatPeer::retrieveByPK($this->id, $con);
		}

		return $this->singleProductsCat;
	}

	
	public function setProductsCat(ProductsCat $v)
	{
		$this->singleProductsCat = $v;

				if ($v->getProducts() === null) {
			$v->setProducts($this);
		}

		return $this;
	}

	
	public function clearProductsComsRelatedByProduct()
	{
		$this->collProductsComsRelatedByProduct = null; 	}

	
	public function initProductsComsRelatedByProduct()
	{
		$this->collProductsComsRelatedByProduct = array();
	}

	
	public function getProductsComsRelatedByProduct($criteria = null, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ProductsPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collProductsComsRelatedByProduct === null) {
			if ($this->isNew()) {
			   $this->collProductsComsRelatedByProduct = array();
			} else {

				$criteria->add(ProductsComPeer::PRODUCT, $this->id);

				ProductsComPeer::addSelectColumns($criteria);
				$this->collProductsComsRelatedByProduct = ProductsComPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(ProductsComPeer::PRODUCT, $this->id);

				ProductsComPeer::addSelectColumns($criteria);
				if (!isset($this->lastProductsComRelatedByProductCriteria) || !$this->lastProductsComRelatedByProductCriteria->equals($criteria)) {
					$this->collProductsComsRelatedByProduct = ProductsComPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastProductsComRelatedByProductCriteria = $criteria;
		return $this->collProductsComsRelatedByProduct;
	}

	
	public function countProductsComsRelatedByProduct(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ProductsPeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collProductsComsRelatedByProduct === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(ProductsComPeer::PRODUCT, $this->id);

				$count = ProductsComPeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(ProductsComPeer::PRODUCT, $this->id);

				if (!isset($this->lastProductsComRelatedByProductCriteria) || !$this->lastProductsComRelatedByProductCriteria->equals($criteria)) {
					$count = ProductsComPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collProductsComsRelatedByProduct);
				}
			} else {
				$count = count($this->collProductsComsRelatedByProduct);
			}
		}
		$this->lastProductsComRelatedByProductCriteria = $criteria;
		return $count;
	}

	
	public function addProductsComRelatedByProduct(ProductsCom $l)
	{
		if ($this->collProductsComsRelatedByProduct === null) {
			$this->initProductsComsRelatedByProduct();
		}
		if (!in_array($l, $this->collProductsComsRelatedByProduct, true)) { 			array_push($this->collProductsComsRelatedByProduct, $l);
			$l->setProductsRelatedByProduct($this);
		}
	}

	
	public function clearProductsComsRelatedByProduct2()
	{
		$this->collProductsComsRelatedByProduct2 = null; 	}

	
	public function initProductsComsRelatedByProduct2()
	{
		$this->collProductsComsRelatedByProduct2 = array();
	}

	
	public function getProductsComsRelatedByProduct2($criteria = null, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ProductsPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collProductsComsRelatedByProduct2 === null) {
			if ($this->isNew()) {
			   $this->collProductsComsRelatedByProduct2 = array();
			} else {

				$criteria->add(ProductsComPeer::PRODUCT2, $this->id);

				ProductsComPeer::addSelectColumns($criteria);
				$this->collProductsComsRelatedByProduct2 = ProductsComPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(ProductsComPeer::PRODUCT2, $this->id);

				ProductsComPeer::addSelectColumns($criteria);
				if (!isset($this->lastProductsComRelatedByProduct2Criteria) || !$this->lastProductsComRelatedByProduct2Criteria->equals($criteria)) {
					$this->collProductsComsRelatedByProduct2 = ProductsComPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastProductsComRelatedByProduct2Criteria = $criteria;
		return $this->collProductsComsRelatedByProduct2;
	}

	
	public function countProductsComsRelatedByProduct2(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ProductsPeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collProductsComsRelatedByProduct2 === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(ProductsComPeer::PRODUCT2, $this->id);

				$count = ProductsComPeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(ProductsComPeer::PRODUCT2, $this->id);

				if (!isset($this->lastProductsComRelatedByProduct2Criteria) || !$this->lastProductsComRelatedByProduct2Criteria->equals($criteria)) {
					$count = ProductsComPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collProductsComsRelatedByProduct2);
				}
			} else {
				$count = count($this->collProductsComsRelatedByProduct2);
			}
		}
		$this->lastProductsComRelatedByProduct2Criteria = $criteria;
		return $count;
	}

	
	public function addProductsComRelatedByProduct2(ProductsCom $l)
	{
		if ($this->collProductsComsRelatedByProduct2 === null) {
			$this->initProductsComsRelatedByProduct2();
		}
		if (!in_array($l, $this->collProductsComsRelatedByProduct2, true)) { 			array_push($this->collProductsComsRelatedByProduct2, $l);
			$l->setProductsRelatedByProduct2($this);
		}
	}

	
	public function clearStockcurrents()
	{
		$this->collStockcurrents = null; 	}

	
	public function initStockcurrents()
	{
		$this->collStockcurrents = array();
	}

	
	public function getStockcurrents($criteria = null, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ProductsPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collStockcurrents === null) {
			if ($this->isNew()) {
			   $this->collStockcurrents = array();
			} else {

				$criteria->add(StockcurrentPeer::PRODUCT, $this->id);

				StockcurrentPeer::addSelectColumns($criteria);
				$this->collStockcurrents = StockcurrentPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(StockcurrentPeer::PRODUCT, $this->id);

				StockcurrentPeer::addSelectColumns($criteria);
				if (!isset($this->lastStockcurrentCriteria) || !$this->lastStockcurrentCriteria->equals($criteria)) {
					$this->collStockcurrents = StockcurrentPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastStockcurrentCriteria = $criteria;
		return $this->collStockcurrents;
	}

	
	public function countStockcurrents(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ProductsPeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collStockcurrents === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(StockcurrentPeer::PRODUCT, $this->id);

				$count = StockcurrentPeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(StockcurrentPeer::PRODUCT, $this->id);

				if (!isset($this->lastStockcurrentCriteria) || !$this->lastStockcurrentCriteria->equals($criteria)) {
					$count = StockcurrentPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collStockcurrents);
				}
			} else {
				$count = count($this->collStockcurrents);
			}
		}
		$this->lastStockcurrentCriteria = $criteria;
		return $count;
	}

	
	public function addStockcurrent(Stockcurrent $l)
	{
		if ($this->collStockcurrents === null) {
			$this->initStockcurrents();
		}
		if (!in_array($l, $this->collStockcurrents, true)) { 			array_push($this->collStockcurrents, $l);
			$l->setProducts($this);
		}
	}


	
	public function getStockcurrentsJoinLocations($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ProductsPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collStockcurrents === null) {
			if ($this->isNew()) {
				$this->collStockcurrents = array();
			} else {

				$criteria->add(StockcurrentPeer::PRODUCT, $this->id);

				$this->collStockcurrents = StockcurrentPeer::doSelectJoinLocations($criteria, $con, $join_behavior);
			}
		} else {
									
			$criteria->add(StockcurrentPeer::PRODUCT, $this->id);

			if (!isset($this->lastStockcurrentCriteria) || !$this->lastStockcurrentCriteria->equals($criteria)) {
				$this->collStockcurrents = StockcurrentPeer::doSelectJoinLocations($criteria, $con, $join_behavior);
			}
		}
		$this->lastStockcurrentCriteria = $criteria;

		return $this->collStockcurrents;
	}

	
	public function clearStockdiarys()
	{
		$this->collStockdiarys = null; 	}

	
	public function initStockdiarys()
	{
		$this->collStockdiarys = array();
	}

	
	public function getStockdiarys($criteria = null, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ProductsPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collStockdiarys === null) {
			if ($this->isNew()) {
			   $this->collStockdiarys = array();
			} else {

				$criteria->add(StockdiaryPeer::PRODUCT, $this->id);

				StockdiaryPeer::addSelectColumns($criteria);
				$this->collStockdiarys = StockdiaryPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(StockdiaryPeer::PRODUCT, $this->id);

				StockdiaryPeer::addSelectColumns($criteria);
				if (!isset($this->lastStockdiaryCriteria) || !$this->lastStockdiaryCriteria->equals($criteria)) {
					$this->collStockdiarys = StockdiaryPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastStockdiaryCriteria = $criteria;
		return $this->collStockdiarys;
	}

	
	public function countStockdiarys(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ProductsPeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collStockdiarys === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(StockdiaryPeer::PRODUCT, $this->id);

				$count = StockdiaryPeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(StockdiaryPeer::PRODUCT, $this->id);

				if (!isset($this->lastStockdiaryCriteria) || !$this->lastStockdiaryCriteria->equals($criteria)) {
					$count = StockdiaryPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collStockdiarys);
				}
			} else {
				$count = count($this->collStockdiarys);
			}
		}
		$this->lastStockdiaryCriteria = $criteria;
		return $count;
	}

	
	public function addStockdiary(Stockdiary $l)
	{
		if ($this->collStockdiarys === null) {
			$this->initStockdiarys();
		}
		if (!in_array($l, $this->collStockdiarys, true)) { 			array_push($this->collStockdiarys, $l);
			$l->setProducts($this);
		}
	}


	
	public function getStockdiarysJoinLocations($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ProductsPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collStockdiarys === null) {
			if ($this->isNew()) {
				$this->collStockdiarys = array();
			} else {

				$criteria->add(StockdiaryPeer::PRODUCT, $this->id);

				$this->collStockdiarys = StockdiaryPeer::doSelectJoinLocations($criteria, $con, $join_behavior);
			}
		} else {
									
			$criteria->add(StockdiaryPeer::PRODUCT, $this->id);

			if (!isset($this->lastStockdiaryCriteria) || !$this->lastStockdiaryCriteria->equals($criteria)) {
				$this->collStockdiarys = StockdiaryPeer::doSelectJoinLocations($criteria, $con, $join_behavior);
			}
		}
		$this->lastStockdiaryCriteria = $criteria;

		return $this->collStockdiarys;
	}

	
	public function clearTicketliness()
	{
		$this->collTicketliness = null; 	}

	
	public function initTicketliness()
	{
		$this->collTicketliness = array();
	}

	
	public function getTicketliness($criteria = null, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ProductsPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collTicketliness === null) {
			if ($this->isNew()) {
			   $this->collTicketliness = array();
			} else {

				$criteria->add(TicketlinesPeer::PRODUCT, $this->id);

				TicketlinesPeer::addSelectColumns($criteria);
				$this->collTicketliness = TicketlinesPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(TicketlinesPeer::PRODUCT, $this->id);

				TicketlinesPeer::addSelectColumns($criteria);
				if (!isset($this->lastTicketlinesCriteria) || !$this->lastTicketlinesCriteria->equals($criteria)) {
					$this->collTicketliness = TicketlinesPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastTicketlinesCriteria = $criteria;
		return $this->collTicketliness;
	}

	
	public function countTicketliness(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ProductsPeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collTicketliness === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(TicketlinesPeer::PRODUCT, $this->id);

				$count = TicketlinesPeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(TicketlinesPeer::PRODUCT, $this->id);

				if (!isset($this->lastTicketlinesCriteria) || !$this->lastTicketlinesCriteria->equals($criteria)) {
					$count = TicketlinesPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collTicketliness);
				}
			} else {
				$count = count($this->collTicketliness);
			}
		}
		$this->lastTicketlinesCriteria = $criteria;
		return $count;
	}

	
	public function addTicketlines(Ticketlines $l)
	{
		if ($this->collTicketliness === null) {
			$this->initTicketliness();
		}
		if (!in_array($l, $this->collTicketliness, true)) { 			array_push($this->collTicketliness, $l);
			$l->setProducts($this);
		}
	}


	
	public function getTicketlinessJoinTickets($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ProductsPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collTicketliness === null) {
			if ($this->isNew()) {
				$this->collTicketliness = array();
			} else {

				$criteria->add(TicketlinesPeer::PRODUCT, $this->id);

				$this->collTicketliness = TicketlinesPeer::doSelectJoinTickets($criteria, $con, $join_behavior);
			}
		} else {
									
			$criteria->add(TicketlinesPeer::PRODUCT, $this->id);

			if (!isset($this->lastTicketlinesCriteria) || !$this->lastTicketlinesCriteria->equals($criteria)) {
				$this->collTicketliness = TicketlinesPeer::doSelectJoinTickets($criteria, $con, $join_behavior);
			}
		}
		$this->lastTicketlinesCriteria = $criteria;

		return $this->collTicketliness;
	}


	
	public function getTicketlinessJoinTaxes($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ProductsPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collTicketliness === null) {
			if ($this->isNew()) {
				$this->collTicketliness = array();
			} else {

				$criteria->add(TicketlinesPeer::PRODUCT, $this->id);

				$this->collTicketliness = TicketlinesPeer::doSelectJoinTaxes($criteria, $con, $join_behavior);
			}
		} else {
									
			$criteria->add(TicketlinesPeer::PRODUCT, $this->id);

			if (!isset($this->lastTicketlinesCriteria) || !$this->lastTicketlinesCriteria->equals($criteria)) {
				$this->collTicketliness = TicketlinesPeer::doSelectJoinTaxes($criteria, $con, $join_behavior);
			}
		}
		$this->lastTicketlinesCriteria = $criteria;

		return $this->collTicketliness;
	}

	
	public function clearAllReferences($deep = false)
	{
		if ($deep) {
			if ($this->singleProductsCat) {
				$this->singleProductsCat->clearAllReferences($deep);
			}
			if ($this->collProductsComsRelatedByProduct) {
				foreach ((array) $this->collProductsComsRelatedByProduct as $o) {
					$o->clearAllReferences($deep);
				}
			}
			if ($this->collProductsComsRelatedByProduct2) {
				foreach ((array) $this->collProductsComsRelatedByProduct2 as $o) {
					$o->clearAllReferences($deep);
				}
			}
			if ($this->collStockcurrents) {
				foreach ((array) $this->collStockcurrents as $o) {
					$o->clearAllReferences($deep);
				}
			}
			if ($this->collStockdiarys) {
				foreach ((array) $this->collStockdiarys as $o) {
					$o->clearAllReferences($deep);
				}
			}
			if ($this->collTicketliness) {
				foreach ((array) $this->collTicketliness as $o) {
					$o->clearAllReferences($deep);
				}
			}
		} 
		$this->singleProductsCat = null;
		$this->collProductsComsRelatedByProduct = null;
		$this->collProductsComsRelatedByProduct2 = null;
		$this->collStockcurrents = null;
		$this->collStockdiarys = null;
		$this->collTicketliness = null;
			$this->aCategories = null;
			$this->aTaxcategories = null;
	}

} 